var vue = new Vue({
  el: '#app',
  data: {
    multipleSelection: [],
    title: '',
    days: '',
    record: '',
    demandData: [],
    spanArr: [],
    pos: 0,
    totalSize: 0,
    pageIndex: 1,
    pageSize: 10,
    totalSize1: 0,
    pageIndex1: 1,
    pageSize1: 10

  },
  created: function() {
    this.initGrid()
  },
  mounted() {

  },

  methods: {
    // 初始化表格
    initGrid: function() {
      var that = this
      $.post('specialitydemand/listByPageByDate', {
        index: that.pageIndex,
        size: that.pageSize
      }, function(result) {
        console.log(result)
        that.totalSize = result.data.total
        that.demandData = result.data.data
        that.getSpanArr(that.demandData)
      })
    },
    getSpanArr(data) {
      for (var i = 0; i < data.length; i++) {
        if (i === 0) {
          this.spanArr.push(1)
          this.pos = 0
        } else {     // 判断当前元素与上一个元素是否相同
          if (data[i]['id_main'] === data[i - 1]['id_main']) {
            this.spanArr[this.pos] += 1
            this.spanArr.push(0)
          } else {
            this.spanArr.push(1)
            this.pos = i
          }
        }
      }
    },
    arraySpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex <= 5 && columnIndex > 1) {
        const _row = this.spanArr[rowIndex]
        const _col = _row > 0 ? 1 : 0
        return {
          rowspan: _row,
          colspan: _col
        }
      }
    },
    //翻页
    handleSizeChange(val) {
      this.pageSize = val
      this.initGrid()
    },
    //改变每页显示条数
    handleCurrentChange(val) {
      this.pageIndex = val
      this.initGrid()
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    }
  }
})
